package com.lcq.demo;

import org.junit.Test;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @ClassName ModelReportExportTest
 * @Description
 * @Author lichuanqi
 * @Date 2022/3/16 13:59
 * @Version 1.0
 **/
public class ModelReportExportTest {
    @Test
    public void test() throws IOException {
        String outFileLocation = "E:/test/modelReport.docx";
        String templateFileLocation = "E:/test/modelReportTemplate.docx";
        Map<String, Object> paraMap = new HashMap<>();
        Map<String, Object> wordDataMap = new HashMap<>();
        wordDataMap.put("parametersMap", paraMap);

        paraMap.put("reportNum", "report111");
        paraMap.put("checkTime", "2022年3月10日");
        paraMap.put("applyCheckOrg", "送检单位1");
        paraMap.put("checkOrg", "检测单位1");
        paraMap.put("nowTime", "2022年3月16日");
        paraMap.put("prjName", "大兴瀛海");
        paraMap.put("prjLocation", "山东济南");
        paraMap.put("applyCheckTime", "2022年3月13日");
        paraMap.put("toolsVersion", "Revit 2019");
        paraMap.put("specList", "□总图  ■建筑  □结构  □电气  □给排水  □通风空调  □燃气  □装配式混凝土结构  □钢结构  □智能化");
        paraMap.put("buildingStage", "□方案设计阶段  □初步设计阶段  ■施工图设计阶段  □深化设计阶段  □竣工阶段");
        paraMap.put("isRespChecked", "是");
        paraMap.put("isClear", "否");
        paraMap.put("isFinal", "是");

        Map<String, Object> deliveryTableMap = new HashMap<>();
        List<Map<String, Object>> deliveryList = new ArrayList<>();
        for (int i = 1; i <= 3; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("orderNum", i);
            map.put("fileName", "deliveryFile"+i);
            map.put("fileType", "rvt");
            map.put("fileSize", i*10+"m");
            map.put("fileMD5", i+"AB"+i);
            deliveryList.add(map);
        }
        deliveryTableMap.put("list", deliveryList);
        wordDataMap.put("deliveryTable", deliveryTableMap);

        Map<String, Object> checkBasisTableMap = new HashMap<>();
        List<Map<String, Object>> checkBasisList = new ArrayList<>();
        for (int i = 1; i <= 3; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("orderNum", i);
            map.put("name", "检测依据"+i);
            map.put("version", "v"+i);
            checkBasisList.add(map);
        }
        checkBasisTableMap.put("list", checkBasisList);
        wordDataMap.put("checkBasisTable", checkBasisTableMap);

        //检测内容
        Map<String, Object> checkContentTableMap = new HashMap<>();
        List<Map<String, Object>> checkContentList = new ArrayList<>();
        for (int i = 1; i <= 3; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("classify", "检测分类"+i);
            map.put("detail", "检测详情"+i+":"+1);
            checkContentList.add(map);

            Map<String, Object> map1 = new HashMap<>();
            map1.put("classify", "检测分类"+i);
            map1.put("detail", "检测详情"+i+":"+2);
            checkContentList.add(map1);

            Map<String, Object> map2 = new HashMap<>();
            map2.put("classify", "检测分类"+i);
            map2.put("detail", "检测详情"+i+":"+3);
            checkContentList.add(map2);
        }
        checkContentTableMap.put("list", checkContentList);
        wordDataMap.put("checkContentTable", checkContentTableMap);

        paraMap.put("check11", "存储结构111");
        paraMap.put("check12", "符合");
        paraMap.put("check13", "V3.0");

        paraMap.put("check21", "符合");
        paraMap.put("check22", "不符合");
        paraMap.put("check23", "符合");
        paraMap.put("check24", "符合");
        paraMap.put("check25", "不符合");


        paraMap.put("check311", "是");
        paraMap.put("check312", "否");
        paraMap.put("check313", "是");

        paraMap.put("check321", "是");
        paraMap.put("check322", "否");
        paraMap.put("check323", "是");
        paraMap.put("check33", "是");
        paraMap.put("check34", "否");

        paraMap.put("check411", "是");
        paraMap.put("check42", "是");
        paraMap.put("check43", "否");
        paraMap.put("check441", "是");
        paraMap.put("check442", "是");
        paraMap.put("check45", "否");
        paraMap.put("check46", "是");

        paraMap.put("check511", "是");
        paraMap.put("check52", "否");


        Map<String, Object> reportProblemTableMap = new HashMap<>();
        List<Map<String, Object>> reportProblemList = new ArrayList<>();
        for (int i = 1; i <= 3; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("problemClass", "问题分类"+i);
            map.put("problemDesc", "问题描述"+i);
            List<File> pics = new ArrayList<>();
            pics.add(new File("E:/test/problem1.png"));
            pics.add(new File("E:/test/problem2.png"));
            pics.add(new File("E:/test/problem3.png"));
            map.put("$problemPic$", pics);
            reportProblemList.add(map);
        }
        reportProblemTableMap.put("list", reportProblemList);
        wordDataMap.put("reportProblemTable", reportProblemTableMap);

        WordTemplate wordTemplate = WordTemplate.buildTemplate(templateFileLocation);
        wordTemplate.replaceDocument(wordDataMap);
        wordTemplate.writeFile(outFileLocation);

    }
}
